<template>
	<view>
		<view class="bg" style="background-color:#f5fae9 "></view>
		<u-navbar :is-back="true" :title="title" title-color="#529030" :background="background" :border-bottom="false"
			:is-fixed="false" back-icon-color="#529030"> </u-navbar>

		<view class="index_body" v-if="flag == 1">
			<view class="index_title">
				捐赠物品
			</view>
			<view class="index_list">
				<view class="index_item">
					<view class="index_name">
						书籍
					</view>
					<view class="index_num">
						<u-number-box v-model="value1" :disabled="value2 || value3"></u-number-box>
					</view>
				</view>
				<view class="index_item">
					<view class="index_name">
						文具
					</view>
					<view class="index_num">
						<u-number-box v-model="value2" :disabled="value1 || value3"></u-number-box>
					</view>
				</view>
				<view class="index_item">
					<view class="index_name">
						其他
					</view>
					<view class="index_num">
						<u-number-box v-model="value3" :disabled="value2 || value1"></u-number-box>
					</view>
				</view>
				
				<view class="index_item">
					<view class="index_form_label">
						您的姓名
					</view>
					<u-input v-model="form.name" placeholder="请输入您的姓名" :border="false" :clearable="false"
						input-align="right" />
				</view>
				
				<view class="index_item">
					<view class="index_form_label">
						联系方式
					</view>
					<u-input v-model="form.mobile" placeholder="请输入联系方式" :border="false" :clearable="false"
						input-align="right" />
				</view>
			</view>
		</view>
		<view class="index_body" v-if="flag == 2">
			<view class="index_title">
				公益老师招募
			</view>
			<view class="index_list">
				<view class="index_item">
					<view class="index_form_label">
						您的姓名
					</view>
					<u-input v-model="form.name" placeholder="请输入您的姓名" :border="false" :clearable="false"
						input-align="right" />
				</view>

				<view class="index_item">
					<view class="index_form_label">
						联系方式
					</view>
					<u-input v-model="form.mobile" placeholder="请输入联系方式" :border="false" :clearable="false"
						input-align="right" />
				</view>


				<view class="index_item">
					<view class="index_form_label">
						现居城市
					</view>
					<u-input v-model="form.city" placeholder="请输入现居城市" :border="false" :clearable="false"
						input-align="right" />
				</view>

				<view class="index_item">
					<view class="index_form_label">
						教学内容
					</view>
					<u-input v-model="form.jxcontent" placeholder="请输入教学内容" :border="false" :clearable="false"
						input-align="right" />
				</view>

				<view class="index_item">
					<view class="index_form_label">
						教学经验
					</view>
					<u-input v-model="form.jxjy" placeholder="请输入教学经验" :border="false" :clearable="false"
						input-align="right" />
				</view>

			</view>
		</view>

		<view class="btn_group">
			<view class="btn_submit" @click="toSubmit">
				确定提交
			</view>
		</view>

	</view>

</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: "transparent",
				},
				value1: 0,
				value2: 0,
				value3: 0,
				form: {
					name: '',
					mobile: '',
					city: '',
					jxcontent: '',
					jxjy: '',
				},
				type: '',
				title: '捐赠助力',
				flag:'',
			}
		},
		onLoad(option) {
			this.flag = option.type
			if (this.flag == 1) {
				this.title = '捐赠助力'
			} else {
				this.title = '志愿者招募'
			}
		},
		methods: {

			toSubmit() {
				if (this.flag == 2) {
					if (!this.form.name) {
						this.$u.toast('请填写您的名字');
						return
					}
					if (!this.form.mobile) {
						this.$u.toast('请填写联系方式');
						return
					}
					if (!this.form.city) {
						this.$u.toast('请填写现居城市');
						return
					}
					if (!this.form.jxcontent) {
						this.$u.toast('请填写教学内容');
						return
					}
					if (!this.form.jxjy) {
						this.$u.toast('请填写教学经验');
						return
					}
				}

				if (this.flag == 1) {
					var type = ''
					var num = 0
					if (this.value1) {
						type = '书籍'
						num = this.value1
					}
					if (this.value2) {
						type = '文具'
						num = this.value2
					}
					if (this.value3) {
						type = '其他'
						num = this.value3
					}

					if (!type || num == 0) {
						this.$u.toast('请选择需要捐赠的物品');
						return
					}
				}

				this.$api.uerHelpAdd({
					...this.form,
					type: type,
					flag: this.flag,
					num: num
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						uni.showToast({
							title: '保存成功',
							mask: true
						});
						setTimeout(e => {
							uni.navigateBack()
						}, 2000)
						console.log(res)
					} else {
						this.$u.toast('稍后重试');
					}

				})

			}
		}
	}
</script>
<style>
	page {
		background-color: #f5fae9;
		/*** f4f6f8 **/
	}
</style>
<style scoped lang="scss">
	.index_body {
		padding: 24rpx;
		margin: 24rpx;
		background-color: #fff;
		border-radius: 24rpx;

		.index_title {
			font-weight: 500;
			font-size: 28rpx;
			color: #000000;
			font-style: normal;
			text-transform: none;
		}

		.index_name {
			font-weight: 500;
			font-size: 24rpx;
			color: #33333399;
			font-style: normal;
			text-transform: none;
		}

		.index_form_label {
			// font-size: 26rpx;
			color: #000000;
			font-style: normal;
		}

		.index_list {
			display: flex;
			flex-direction: column;

			.index_item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 20rpx 10rpx;
				border-bottom: 1rpx solid #efefef;
			}
		}
	}

	.btn_group {
		margin: 24rpx;
		padding-bottom: 100rpx;

		.btn_submit {
			background: #529030; // #f5fae9  529030
			color: #fff;
			text-align: center;
			border-radius: 50rpx;
			padding: 20rpx;
		}
	}
</style>